package cn.tworice.config;

import cn.tworice.interceptor.AdminInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    public AdminInterceptor adminInterceptor(){
        return new AdminInterceptor();
    }

    /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminInterceptor())
                .addPathPatterns("/admin/**")   // 拦截请求
                .excludePathPatterns("/admin/login/**","/admin/posts/degree","/admin/companies/typeList","/admin/notice/list");    // 放行请求
    }
}
